package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.pro.Process;
import com.qidianit.mes.pro.service.ProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/process")
@CrossOrigin
public class ProcessController {
    @Autowired
    private ProcessService processService;
    @GetMapping("page")
    public Result<PageInfo<Process>>
    list(Process  process, @RequestParam(defaultValue = "1")int page,
                            @RequestParam(defaultValue = "10")int size){
        return processService.selectList(process,page,size);
    }

    @PostMapping("/add")
    public Result<Process> saveProcess(@RequestBody Process process){
       // System.out.println(process);
        return processService.saveProcess(process);
    }

    @GetMapping("/code/{code}")
    public Result<Process> selectByCode(@PathVariable("code") String processCode){
        return processService.selectByCode(processCode);
    }

    @PutMapping("/update")
    public Result<Process> updateById(@RequestBody  Process process){
        return processService.updateById(process);
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable("id") Long id){
        return processService.deleteById(id);
    }

    @DeleteMapping("/batchDelete")
    public Result batchDelete(Long[] id){
        return processService.batchDelete(id);
    }

}
